package com.anolesoft.amljmes.billing.service.impl;

import com.anolesoft.amljmes.billing.controller.GdyjDykhxController;
import com.anolesoft.amljmes.billing.dto.GdyjDykhxDto;
import com.anolesoft.amljmes.billing.service.GdyjDykhxService;
import com.anolesoft.amljmes.billing.service.mapper.GdyjDykhxServiceMapper;
import com.anolesoft.common.core.domain.LoginUser;
import com.anolesoft.common.security.util.SecurityUtils;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GdyjDykhxServiceImpl implements GdyjDykhxService {
    @Autowired
    GdyjDykhxServiceMapper gdyjDykhxServiceMapper;
    @Autowired
    private SqlSessionTemplate sqlSessionTemplate;

    @Override
    public List<GdyjDykhxDto> queryGdyjDykhxInfo(GdyjDykhxController.DemoVO demoVO) {
        List<GdyjDykhxDto> gdyjDykhxDtoList=gdyjDykhxServiceMapper.queryGdyjDykhxSQL(demoVO);
        return gdyjDykhxDtoList;
    }

    @Override
    public int addGdyjDykhx(GdyjDykhxDto inFoDtoParam) {
        int count = gdyjDykhxServiceMapper.addGdyjDykhx(inFoDtoParam);
        return count;
    }

    @Override
    public int delete(List<String> objuids) {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        String scr=loginUser.getEmpUid();
        int count = 0;
        for(String objuid : objuids) {
            count += gdyjDykhxServiceMapper.delete(objuid,scr);
        }
        return count;
    }

    @Override
    public void uploadExcel(List<GdyjDykhxDto> list) {
        SqlSession sqlSession = sqlSessionTemplate.getSqlSessionFactory().openSession(ExecutorType.BATCH, false);
        GdyjDykhxServiceMapper gdyjDykhxServiceMapper = sqlSession.getMapper(GdyjDykhxServiceMapper.class);
        list.forEach(a -> {
            gdyjDykhxServiceMapper.insert(a);
        });
        sqlSession.commit();
    }

    @Override
    public int isGdyjDykhxName(GdyjDykhxDto inFoDtoPara) {
        int count = gdyjDykhxServiceMapper.isGdyjDykhxName(inFoDtoPara);
        return count;
    }

}
